using System;
using System.Collections.Generic;
using System.Text;

using System.Data;
using System.Data.Common;

using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Caching;

using Husb.Data;
using Husb.DataUtil;

using CentralOffice.Enterprise.Data;
using NoticeReplyTable = CentralOffice.Enterprise.Data.NoticeReplyDataSet.NoticeReplyDataTable;
using NoticeReplyRow = CentralOffice.Enterprise.Data.NoticeReplyDataSet.NoticeReplyRow;


namespace CentralOffice.Enterprise.DataAccess
{
    public class NoticeReplyAdapter : DataAccessAdapter<NoticeReplyDataSet, NoticeReplyTable, NoticeReplyRow>
    {
        public const string FetchByReplyByEnterpriseIdStoredProc = "Enterprise.NoticeReply_SelectNoticeReplyByEnterpriseId";
        public const string FetchByReplyByNoticeIdStoredProc = "Enterprise.NoticeReply_SelectNoticeReplyByNoticeId";
        public NoticeReplyAdapter()
        {
            this.TableName = "NoticeReply";

            GetAllStoredProc = "Enterprise.NoticeReply_SelectNoticeRepliesAll";
            InsertStoredProc = "Enterprise.NoticeReply_InsertNoticeReply";
            UpdateStoredProc = "Enterprise.NoticeReply_UpdateNoticeReply";
            DeleteStoredProc = "Enterprise.NoticeReply_DeleteNoticeReply";

            GetByIdStoredProc = "Enterprise.NoticeReply_SelectNoticeReply";
            GetByNameStoredProc = "";
            GetPagedStoredProc = "Enterprise.NoticeReply_SelectNoticeRepliesPaged";
            GetRowCountStoredProc = "Enterprise.NoticeReply_SelectNoticeRepliesRowCount";

            FindStoredProc = "Enterprise.NoticeReply_SelectNoticeRepliesDynamic";

        }

        protected override void PopulateInsertParameters(Database db, DbCommand cmd)
        {
            //throw new Exception("The method or operation is not implemented.");
            db.AddInParameter(cmd, "Id", DbType.Guid, "Id", DataRowVersion.Current);
            db.AddInParameter(cmd, "NoticeId", DbType.Guid, "NoticeId", DataRowVersion.Current);
            db.AddInParameter(cmd, "EnterpriseId", DbType.Guid, "EnterpriseId", DataRowVersion.Current);
            db.AddInParameter(cmd, "ReceiverId", DbType.Guid, "ReceiverId", DataRowVersion.Current);
            
            db.AddInParameter(cmd, "ReplyBy", DbType.AnsiString, "ReplyBy", DataRowVersion.Current);
            db.AddInParameter(cmd, "ReplyDate", DbType.DateTime, "ReplyDate", DataRowVersion.Current);
            db.AddInParameter(cmd, "ReplyText", DbType.String, "ReplyText", DataRowVersion.Current);
            db.AddInParameter(cmd, "Attachments", DbType.String, "Attachments", DataRowVersion.Current);
            db.AddInParameter(cmd, "ReplyType", DbType.Int32, "ReplyType", DataRowVersion.Current);
            
        }

        public NoticeReplyTable FetchByEnterpriseId(Guid noticeId, Guid enterpriseId)
        {
            List<DatabaseParameter> parameters = new List<DatabaseParameter>();
            parameters.Add(new DatabaseParameter("NoticeId", DbType.Guid, noticeId));
            parameters.Add(new DatabaseParameter("EnterpriseId", DbType.Guid, enterpriseId));
            
            return this.GetTable(FetchByReplyByEnterpriseIdStoredProc, parameters, true, false, null);
        }

        public NoticeReplyTable FetchByNoticeId(Guid noticeId)
        {
            List<DatabaseParameter> parameters = new List<DatabaseParameter>();
            parameters.Add(new DatabaseParameter("NoticeId", DbType.Guid, noticeId));

            return this.GetTable(FetchByReplyByNoticeIdStoredProc, parameters, true, false, null);
        }
    }
}
